#!/usr/bin/python
# encoding: utf-8
'''
@File    :   code.py
@Time    :   2020/03/11 21:54:19
@Author  :   fangkaijin 
@Version :   1.0
@Contact :   fangkaijin@gmail.com
@License :   杭州移动互联
@Desc    :   None
'''

# 导入库包

import sys, os
from splinter import Browser, driver
from splinter import driver
from time import sleep
from time import time

# home_url = 'https://www.baidu.com'
# b = Browser('chrome')
# b.visit(home_url)
# sleep(5)
# i = b.find_by_id('kw').first
# i.fill('金瓶梅')
# sleep(3)
# bu = b.find_by_id('su').first
# bu.click()
# b.quit()

import httplib2
from urllib3 import request
import urllib3
from urllib import parse
import smtplib
from email.mime.text import MIMEText
import time


def sendSms(mobile, sms_info):
    """发送手机通知短信，用的是-互亿无线-的测试短信"""
    host = "106.ihuyi.com"
    sms_send_uri = "/webservice/sms.php?method=Submit"
    account = "C59782899"
    pass_word = "19d4d9c0796532c7328e8b82e2812655"
    params = parse.urlencode(
        {'account': account, 'password': pass_word, 'content': sms_info, 'mobile': mobile, 'format': 'json'}
    )
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    conn = httplib2.HTTPConnectionWithTimeout(host, port=80, timeout=30)
    conn.request("POST", sms_send_uri, params, headers)
    response = conn.getresponse()
    response_str = response.read()
    conn.close()
    return response_str

def sendEmail(receiver_address, content):
    """发送邮件通知"""
    # 连接邮箱服务器信息
    host = 'smtp.163.com'
    port = 25
    sender = 'gxcuizy@163.com'  # 你的发件邮箱号码
    pwd = 'FatBoy666'  # 不是登陆密码，是客户端授权密码
    # 发件信息
    receiver = receiver_address
    body = '<h2>温馨提醒：</h2><p>' + content + '</p>'
    msg = MIMEText(body, 'html', _charset="utf-8")
    msg['subject'] = '抢票成功通知！'
    msg['from'] = sender
    msg['to'] = receiver
    s = smtplib.SMTP(host, port)
    # 开始登陆邮箱，并发送邮件
    s.login(sender, pwd)
    s.sendmail(sender, receiver, msg.as_string())

url = 'https://www.jianshu.com/'

from bs4 import BeautifulSoup
from urllib3 import *
from urllib import request
import urllib
def searchBaidu():
    h = urllib.request.urlopen(url)
    print(h.read().decode('utf-8'))
    soup = BeautifulSoup(h, 'html.parser')
    postion = soup.findAll('input')
    for p in postion:
        print(p)

if __name__ == '__main__':
    #sendEmail('fhongloving@163.com', 'email发送测试')
    # sendSms('13588741728', '短信测试')
    searchBaidu()